<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="el.Monster" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: xiaofeng
  Date: 2025/5/19
  Time: 21:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
第一种<br/>
<c:forEach begin="1" end="5" var="i" step="2">
    排名=${i}
</c:forEach>

<%
    request.setAttribute("sports",new String[]{"打篮球","乒乓球"});
%>
第二种，遍历数组<br/>
<c:forEach items="${requestScope.sports}" var="sport">
    运动名称=${sport}
</c:forEach>

<%
    HashMap<String, Object> map = new HashMap<>();
    map.put("key1","北京");
    map.put("key2","上海");
    map.put("key3","天津");
    request.setAttribute("cities",map);
%>
第三种遍历Map<br/>
<c:forEach items="${requestScope.cities}" var="city">
    城市信息:${city.key}--${city.value}<br/>
</c:forEach>

<%
    ArrayList<Monster> monsters = new ArrayList<>();
    monsters.add(new Monster(100,"小妖怪","巡山的"));
    monsters.add(new Monster(200, "大妖怪", "做饭的"));
    monsters.add(new Monster(300, "老妖怪", "打扫位置的"));
    request.setAttribute("monsters", monsters);
%>
第4种遍历方式：遍历List<br/>
<c:forEach items="${requestScope.monsters}" var="monster">
    妖怪的信息:${monster.id}-${monster.name}-${monster.skill}<br/>
</c:forEach>
</body>
</html>
